package com.colin.app.activity.other.recycler;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;

import com.colin.app.R;
import com.colin.app.activity.other.OtherContract;
import com.colin.app.activity.other.OtherPresenterImpl;
import com.colin.app.app.AppActivity;
import com.colin.app.bean.DemoBean;
import com.colin.app.bean.ItemBean;
import com.colin.library.help.InitViewHelp;

import java.util.List;

public class RecyclerViewTypeActivity extends AppActivity implements OtherContract.OtherView {
    private OtherContract.OtherPresenter mOtherPresenter = null;
    private SwipeRefreshLayout refresh_view_type;
    private RecyclerView recycler_view_type;
    private List<ItemBean> mItemBeanList;
//    private ItemBeanRecyclerViewAdapter mAdapter = null;

    @Override
    protected void onDestroy() {
        if (null != mOtherPresenter) {
            mOtherPresenter.destroy();
            mOtherPresenter = null;
        }
        super.onDestroy();
    }

    @Override
    public void initPresenter() {
        DemoBean demoBean = getIntent().getExtras().getParcelable("clazz");
        mOtherPresenter = new OtherPresenterImpl(this, this, demoBean);
    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_recycler_view_type;
    }

    @Override
    public void initView() {
        this.refresh_view_type = (SwipeRefreshLayout) this.findViewById(R.id.refresh_view_type);
        this.recycler_view_type = (RecyclerView) this.findViewById(R.id.recycler_view_type);
        InitViewHelp.getInstance().initSwipeRefreshLayout(refresh_view_type);
        initRecyclerView();
    }

    private void initRecyclerView() {
//        int integer = getResources().getInteger(R.integer.grid_columns);
//        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(integer - 1, StaggeredGridLayoutManager.VERTICAL);
//        if (null == mItemBeanList) {
//            mItemBeanList = new ArrayList<>();
//        }
//        if (null == mAdapter) {
//            mAdapter = new ItemBeanRecyclerViewAdapter(this, mItemBeanList);
//        }
//        recycler_view_type.setLayoutManager(layoutManager);
//        recycler_view_type.setAdapter(mAdapter);
//        recycler_view_type.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    public void initData() {
        mOtherPresenter.setData();
    }

    @Override
    public void initListener() {
//        recycler_view_type.addOnScrollListener(new OnRecyclerViewScrollListener<ItemBean>() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onLoadMore() {
//                mAdapter.setViewMoreState(BaseRecyclerAdapter.VIEW_MORE_STATE_LOADING);
//                mAdapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onFinish(List<ItemBean> list) {
//                mAdapter.setViewMoreState(BaseRecyclerAdapter.VIEW_MORE_STATE_FINISH);
//                mAdapter.notifyDataSetChanged();
//            }
//        });
    }

    @Override
    public void initAsync() {
        loadData(true);

    }

    private void loadData(final boolean refresh) {
//        recycler_view_type.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                if (refresh_view_type.isRefreshing()) {
//                    refresh_view_type.setRefreshing(false);
//                }
//                if (refresh) {
//                    mItemBeanList.clear();
//                }
//                mItemBeanList.addAll(mOtherPresenter.listGetItemData(refresh));
//                mAdapter.setViewMoreState(BaseRecyclerAdapter.VIEW_MORE_STATE_FINISH);
//                mAdapter.notifyDataSetChanged();
//            }
//        }, 3000);
    }
}
